<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <script src="js/jquery-3.3.1.min.js"></script>
  <title>Document</title>
  <style>
    * {
      padding: 0;
      margin: 0;
    }
    ul {
      width: 640px;
      height: 341px;
      margin: 0 auto;
      margin-top: 100px;
      margin-bottom: 100px;
    }
    li {
      position: relative;
      float: left;
      width: 25%;
      height: 341px;
      /* background-color: red; */
      list-style: none;
      transform-style: preserve-3d;
      transition: all 0.5s;
    }
    span {
      position: absolute;
      /* border: 1px solid black; */
      width: 100%;
      height: 341px;
      display: block;
    }
    input[type="button"] {
      display: block;
      margin: 0 auto;
      height: 30px;
      width: 100px;
    }
    /* 每张图片的第一部分 */
    ul li:nth-child(1) span:nth-child(1) {
      background: url(img/1.jpg) no-repeat;
      background-size: 640px;
      background-position: 0 0;
      transform: translateZ(170px);
    }
    ul li:nth-child(1) span:nth-child(2) {
      background: url(img/2.jpg) no-repeat;
      background-size: 640px;
      background-position: 0 0;
      transform: translateY(-170px) rotateX(90deg); 
    }
    ul li:nth-child(1) span:nth-child(3) {
      background: url(img/3.jpg) no-repeat;
      background-size: 640px;
      background-position: 0 0;
      transform: translateZ(-170px) rotateX(180deg);
    }
    ul li:nth-child(1) span:nth-child(4) {
      background: url(img/4.jpg) no-repeat;
      background-size: 640px;
      background-position: 0 0;
      transform: translateY(170px) rotateX(-90deg);
    }
    /* 每张图片的第二部分 */
    ul li:nth-child(2) span:nth-child(1) {
      background: url(img/1.jpg) no-repeat;
      background-size: 640px;
      background-position: -160px 0;
      transform: translateZ(170px);
    }
    ul li:nth-child(2) span:nth-child(2) {
      background: url(img/2.jpg) no-repeat;
      background-size: 640px;
      background-position: -160px 0;
      transform: translateY(-170px) rotateX(90deg); 
    }
    ul li:nth-child(2) span:nth-child(3) {
      background: url(img/3.jpg) no-repeat;
      background-size: 640px;
      background-position: -160px 0;
      transform: translateZ(-170px) rotateX(180deg);
    }
    ul li:nth-child(2) span:nth-child(4) {
      background: url(img/4.jpg) no-repeat;
      background-size: 640px;
      background-position: -160px 0;
      transform: translateY(170px) rotateX(-90deg);
    }
    /* 每张图片的第三部分 */
    ul li:nth-child(3) span:nth-child(1) {
      background: url(img/1.jpg) no-repeat;
      background-size: 640px;
      background-position: -320px 0;
      transform: translateZ(170px);
    }
    ul li:nth-child(3) span:nth-child(2) {
      background: url(img/2.jpg) no-repeat;
      background-size: 640px;
      background-position: -320px 0;
      transform: translateY(-170px) rotateX(90deg); 
    }
    ul li:nth-child(3) span:nth-child(3) {
      background: url(img/3.jpg) no-repeat;
      background-size: 640px;
      background-position: -320px 0;
      transform: translateZ(-170px) rotateX(180deg);
    }
    ul li:nth-child(3) span:nth-child(4) {
      background: url(img/4.jpg) no-repeat;
      background-size: 640px;
      background-position: -320px 0;
      transform: translateY(170px) rotateX(-90deg);
    }
    /* 每张图片的第四部分 */
    ul li:nth-child(4) span:nth-child(1) {
      background: url(img/1.jpg) no-repeat;
      background-size: 640px;
      background-position: -480px 0;
      transform: translateZ(170px);
    }
    ul li:nth-child(4) span:nth-child(2) {
      background: url(img/2.jpg) no-repeat;
      background-size: 640px;
      background-position: -480px 0;
      transform: translateY(-170px) rotateX(90deg); 
    }
    ul li:nth-child(4) span:nth-child(3) {
      background: url(img/3.jpg) no-repeat;
      background-size: 640px;
      background-position: -480px 0;
      transform: translateZ(-170px) rotateX(180deg);
    }
    ul li:nth-child(4) span:nth-child(4) {
      background: url(img/4.jpg) no-repeat;
      background-size: 640px;
      background-position: -480px 0;
      transform: translateY(170px) rotateX(-90deg);
    }
  </style>
</head>
<body>
  <ul>
    <li>
      <span></span>
      <span></span>
      <span></span>
      <span></span>
    </li>
    <li>
      <span></span>
      <span></span>
      <span></span>
      <span></span>
    </li>
    <li>
      <span></span>
      <span></span>
      <span></span>
      <span></span>
    </li>
    <li>
      <span></span>
      <span></span>
      <span></span>
      <span></span>
    </li>
  </ul>
  <input type="button" value="下一张">
  <script>
    var index = 0;
    var flag = true;
    var time = new Date();
    
    $("input:button").click(function() {
      if(flag == true) {
        flag = false;
        index++;
        $("li").each(function (i) {
          // 发现is(":animated")好像只能判断animate()动画，但是animate()与transform有兼容问题
          // if ($(this).is(":animated")) {
          //   return;
          // }
          $(this).css({
            "transform": `rotateX(${index * 90}deg)`,
            "transition-delay": (0.002 * i) + "s"
          })
        })
        // 防止用户多次点击，要经过900毫秒才能够再次点击按钮
        setTimeout(function() {
          flag = true;
        },900)
      }
    })
  </script>
</body>
</html>